home *** CD-ROM | disk | FTP | other *** search
/ Electronic Clipper 1995 April / Electronic Clipper 1995-04.iso / pc / pc_users / ideasrc / setup / samples / qtraw.cpp < prev    next >
C/C++ Source or Header  |  1993-04-07  |  6KB  |  161 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // QTRAW.CPP    - QuickTime for Windows Sample Decompressor
  5. //
  6. //                Version 1.1
  7. //
  8. //                (c) 1988-1993 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Windows header files
  14. #include <windows.h>
  15. #include <windowsx.h>
  16.  
  17. // Compiler header files
  18. #include <string.h>
  19.  
  20. // Application header files
  21. #include "prototyp.hp"
  22.  
  23. // Global data
  24. ComponentDescription cdTable[] =            // one component in this DLL
  25.   { ostypeDCMP                              // ostypeComponentType
  26.   , ostypeRAW                               // ostypeComponentSubType
  27.   , ostypeAPPL                              // ostypeComponentManufacturer
  28.   , 0                                       // dwComponentFlags
  29.   , 0                                       // dwComponentFlagsMask
  30.   , ( ComponentRoutine) CodecEntry          // crEntryPoint
  31.   , 0                                       // hrsrcName
  32.   , 0                                       // hrsrcInfo
  33.   , 0                                       // hrsrcIcon
  34.   } ;
  35.  
  36. /* function cfBandDecompress:
  37.    Decompress one frame of the movie
  38. */
  39. ComponentResult QTAPI cfBandDecompress( STKOFF_CMP so
  40.                                       , LPVOID lpvStorage
  41.                                       , LPCODECDECOMPRESSPARAMS lpdecomp
  42.                                       )
  43. {
  44.   ImageDescription FAR * lpIm = lpdecomp->lpim ;
  45.   LPVOID lpCompressed = lpdecomp->lpCompressed
  46.        , lpUncompressed = lpdecomp->lpUncompressed
  47.        ;
  48.   // compute maximum size of uncompressed buffer
  49.   DWORD dwMaxSize = GetSelectorLimit( SELECTOROF( lpUncompressed))
  50.                     - OFFSETOF( lpUncompressed)
  51.                     ;
  52.   LONG lSafeSize = min( lpdecomp->lCompressedSize, ( LONG) dwMaxSize) ;
  53.  
  54.   // act based on sample depth
  55.   if ( lpIm->depth == 16)
  56.     DecompressRaw16( lpCompressed, lpUncompressed, lSafeSize) ;
  57.   else if ( lpCompressed == lpUncompressed) // if source and target agree
  58.     return noErr ;
  59.   else
  60.     CopyMemory( lpUncompressed, lpCompressed, lSafeSize) ;
  61.  
  62.   // successful return
  63.   return noErr ;
  64. }  // cfBandDecompress
  65.  
  66. /* function cfCloseSelect:
  67.    Close an open component instance
  68. */
  69. ComponentResult QTAPI cfCloseSelect( STKOFF_CMP so, ComponentInstance ci)
  70. {
  71.   // free any allocated storage
  72.   LPVOID lpvPrivate = GetComponentInstanceStorage( ci) ;
  73.   FreeMemory( lpvPrivate) ;
  74.  
  75.   // successful return
  76.   return noErr ;
  77. }  // cfCloseSelect
  78.  
  79. /* function cfGetCodecInfo:
  80.    Fill out the codec information block
  81. */
  82. ComponentResult QTAPI cfGetCodecInfo( STKOFF_CMP so
  83.                                     , LPVOID lpvStorage
  84.                                     , LPCODECINFO lpinfo
  85.                                     )
  86. {
  87.   // initialize fields to 0
  88.   _fmemset( lpinfo, 0, sizeof( CODECINFO)) ;
  89.  
  90.   // fill out nonzero fields
  91.   lpinfo->dwDecompressFlags = cdTable[ 0].dwComponentFlags & 0xffffffL ;
  92.   lpinfo->dwFormatFlags = codecInfoDepth1
  93.                           | codecInfoDepth2
  94.                           | codecInfoDepth4
  95.                           | codecInfoDepth8
  96.                           | codecInfoDepth16
  97.                           | codecInfoDepth24
  98.                           | codecInfoDepth32
  99.                           | codecInfoDepth34
  100.                           | codecInfoDepth36
  101.                           | codecInfoDepth40
  102.                           | codecInfoDoesLossless
  103.                           ;
  104.   lpinfo->wDecompressionSpeed = 392 ;
  105.  
  106.   // return to caller
  107.   return noErr ;
  108. }  // cfGetCodecInfo
  109.  
  110. /* function cfOpenSelect:
  111.    Open a codec component instance
  112. */
  113. ComponentResult QTAPI cfOpenSelect( STKOFF_CMP so, ComponentInstance ci)
  114. {
  115.   // allocate and register private storage
  116. #if 0                                       // no private storage for RAW
  117.   LPVOID lpvPrivate = GetMemory( sizeof( RAW)) ;
  118.   if ( lpvPrivate == 0)
  119.     return insufficientMemory ;
  120.   SetComponentInstanceStorage( ci, lpvPrivate) ;
  121. #endif
  122.  
  123.   // successful return
  124.   return noErr ;
  125. }  // cfOpenSelect
  126.  
  127. /* function cfPreDecompress:
  128.    Evaluate the image compression manager's proposed terms
  129. */
  130. ComponentResult QTAPI cfPreDecompress( STKOFF_CMP so
  131.                                      , LPVOID lpvStorage
  132.                                      , LPCODECDECOMPRESSPARAMS lpdecomp
  133.                                      )
  134. {
  135.   // set capabilities
  136.   ImageDescription FAR * lpIm = lpdecomp->lpim ;
  137.   LPCODECCAPABILITIES lpcapab = lpdecomp->lpCapabilities ;
  138.   lpcapab->lFlags = 0 ;                     // cannot do anything
  139.   lpcapab->wBandMin = lpIm->height ;        // no banding
  140.   lpcapab->wBandInc = lpIm->height ;        // no banding
  141.   lpcapab->wExtendHeight = 1 ;              // 1 row per compression unit
  142.   lpcapab->wExtendWidth  = 3 ;              // allow 3 bytes for DWORD access
  143.   lpcapab->wWantedPixelSize = lpIm->depth > 32
  144.                               ? lpIm->depth - 32
  145.                               : lpIm->depth
  146.                               ;
  147.   lpcapab->optt = OPT_RAW ;                 // must decompress to raw
  148.   return lpcapab->optt == lpdecomp->optt ? noErr : codecConditionErr ;
  149. }  // cfPreDecompress
  150.  
  151. /* function cfSequenceBusy:
  152.    Report if an asynchronous operation is active
  153. */
  154. ComponentResult QTAPI cfSequenceBusy( STKOFF_CMP so
  155.                                     , LPVOID lpvStorage
  156.                                     , ImageSequence seq
  157.                                     )
  158. {
  159.   return FALSE ;                            // no asynchronous operations
  160. }  // cfSequenceBusy
  161.